﻿package actions {
	import flash.display.MovieClip;
	import com.Dolar;
	import flash.utils.setInterval;
	import caurina.transitions.Tweener;
	
	public class GetMoney extends MovieClip {
		public function GetMoney() {
			this.Start(100);
		}
		
		private var _items:Vector.<Dolar> = new Vector.<Dolar>();
		public function Start(count:int){
			var i:int = 0;
			for(i = 0; i<this.numChildren; i++){
				//this.removeChild(this.getChildAt(0));
			}
			for(i = 0; i<count; i++){
				_items.push(new Dolar());
				//_items[i].alpha = 0;
				this.addChild(_items[i]);
			}
			
			this.run();
		}
		
		private function run(){
			for each(var item:Dolar in _items){
				this.tween(item);
			}
		}
		
		private function tween(d:Dolar){
			var xpos:int = Helpers.Random(-200, 200);
			var ypos:int = Helpers.Random(-500, -600);
			d.x = xpos;
			d.y = ypos;
			
			Tweener.addTween(d, {time:Math.random()*10 + 3, x:Helpers.Random(-50, 50), y:0, transition:"easeInQuint", onComplete:main_complete, onCompleteParams:[d]});
			Tweener.addTween(d, {time:Helpers.Random(2, 5), alpha:Math.random(), transition:"easeInQuint"});
		}
		
		private function main_complete(d:Dolar){
			d.TweenCount++;
			if(d.TweenCount >= 1){
				d.TweenCount = 0;
				this.tween(d);
			}
		}
	}
}
